import { createRouter, createWebHashHistory } from "vue-router";

// 异步导入组件
const Layout = () => import("@/views/Layout");
const Home = () => import("@/views/home/page-home");
const TopCategory = () => import("@/views/category/top-category");
const SubCategory = () => import("@/views/category/sub-category");

// 路由规则
const routes = [{
    path: "/",
    component: Layout,
    children: [
        {
            path: "/",
            component: Home
        },
        {
            path: "/category/:id",
            component: TopCategory
        },
        {
            path: "/category/sub/:id",
            component: SubCategory
        }
    ]
}];

// 创建路由
// Vue2.0 new VueRouter();
// Vue3.0 createRouter();
const router = createRouter({
    // 创建一个哈希路由
    history: createWebHashHistory(),
    routes
});

export default router;
